package com.portal.innovation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.portal.innovation.common.Constant;
import com.portal.innovation.utils.PageUtils;
import com.portal.innovation.dao.DictionaryConfigDao;
import com.portal.innovation.pojo.DictionaryConfig;
import com.portal.innovation.service.DictionaryConfigService;
import org.springframework.stereotype.Service;

import java.util.HashMap;


@Service("dictionaryConfigService")
public class DictionaryConfigServiceImpl extends ServiceImpl<DictionaryConfigDao, DictionaryConfig> implements DictionaryConfigService {


    @Override
    public PageUtils queryPage(HashMap params) {
        Integer curPage = 1;
        Integer limit = 10;

        if(params.get(Constant.PAGE) != null){
            curPage = Integer.parseInt(params.get(Constant.PAGE).toString());
        }
        if(params.get(Constant.LIMIT) != null){
            limit = Integer.parseInt(params.get(Constant.LIMIT).toString());
        }
        //分页对象
        Page<DictionaryConfig> page = new Page<>(curPage, limit);

        QueryWrapper<DictionaryConfig> condition = new QueryWrapper<>();
        if(params.get("remark") != null){
            String key = params.get("remark").toString();
            if(StringUtils.isNotEmpty(key)){
                condition.like("remark", key);
            }
        }
        PageUtils pageUtils = new PageUtils(this.page(page, condition));
        return pageUtils;
    }

    @Override
    public String getValue(String key) {
        QueryWrapper<DictionaryConfig> condition = new QueryWrapper<>();
        condition.eq("param_key", key);
        DictionaryConfig one = getOne(condition);
        return one.getParamValue();
    }
}